package cn.e4j.modular.crm.controller.bb;

import cn.e4j.core.base.controller.BaseController;
import cn.e4j.core.common.exception.BizExceptionEnum;
import cn.e4j.core.dto.Dtos;
import cn.e4j.core.dto.impl.Dto;
import cn.e4j.core.dto.requestDtoResolver.DtoParam;
import cn.e4j.core.dto.requestDtoResolver.DtoWapper;
import cn.e4j.core.reqres.response.ErrorResponseData;
import cn.e4j.core.reqres.response.PageReData;
import cn.e4j.core.reqres.response.ResponseData;
import cn.e4j.core.reqres.response.SuccessResponseData;
import cn.e4j.core.shiro.ShiroKit;
import cn.e4j.core.shiro.ShiroUser;
import cn.e4j.modular.api.service.BfcglService;
import cn.e4j.modular.crm.entity.GwaaT;
import cn.e4j.modular.crm.service.impl.Gwai120ServiceImpl;
import cn.e4j.modular.system.entity.SysUser;
import cn.e4j.modular.system.service.impl.SystemServiceImpl;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;

/**
 * 拜访成功率
 *
 * @author caijy
 * @Date 20191203
 */
@Controller
@RequestMapping("/bb/bfcgl")
public class BbBfcglController extends BaseController {


    @Autowired
    SystemServiceImpl systemService;

    @Autowired
    BfcglService bfcglService;


    /**
     * 跳转页面
     */
    @RequiresPermissions("bb:bfcgl:init")
    @RequestMapping(value = {"", "init"})
    public String index() {
        return "/pc/crm/bb/bfcgl.html";
    }

    /**
     * 查询列表数据
     */
    @RequiresPermissions("bb:bfcgl:init")
    @ResponseBody
    @RequestMapping(value = "getInfo")
    public Dto getInfo(@DtoParam DtoWapper wapper) {
        Dto inDto = wapper.getDto();
        ShiroUser shiroUser = ShiroKit.getUser();
        List<Dto> result = new ArrayList<>();
        Dto outDto = Dtos.newDto();
        try {

            SysUser currentUser = new SysUser();
            currentUser.setID(shiroUser.getID());
            currentUser.setORG_ID(shiroUser.getORG_ID());
            inDto.put("USERID", currentUser.getID());

            //上下级权限
            Dto sys003 = systemService.getSys003(currentUser);
            List<Dto> listOrg = (List<Dto>) sys003.get("ORGS");
            inDto.put("ORGS", listOrg);

            Dto sys004 = systemService.getSys004(currentUser, listOrg);
            inDto.put("YWY",sys004.get("YWY"));

            result = bfcglService.getInfo(inDto);
            outDto.put("data",result);
            outDto.put("code",0);
        } catch (Exception e) {
            e.printStackTrace();
            outDto.put("code",500);
            return outDto;
        }
        return  outDto;
    }

}
